<?php

class Admin_ChangepassController extends Australian_Controller_Action {

    // Mang tham so nhan duoc o moi Action
    protected $_arrParam;
    // Duong dan cua Controller
    protected $_currentController;
    // Duong dan cua Action chinh
    protected $_actionMain;
    protected $_namespace;
    // Tong so phan trang
    protected $_paginator = array('itemCountPerPage' => 5, 'pageRange' => 3);

    public function init() {
        // Mang tham so nhan duoc o moi Action
        $this->_arrParam = $this->_request->getParams();

        // Duong dan cua Controller
        $this->_currentController = '/' . $this->_arrParam['module']
                . '/' . $this->_arrParam['controller'];

        // Duong dan cua Action chinh
        $this->_actionMain = '/' . $this->_arrParam['module']
                . '/' . $this->_arrParam['controller'] . '/index';

        $this->_paginator['currentPage'] = $this->_request->getParam('page', 1);
        $this->_arrParam['paginator'] = $this->_paginator;

        // Luu cac du lieu filter vao SESSION
        // Dat ten SESSION
        $this->_namespace = $this->_arrParam['module'] . '-' . $this->_arrParam['controller'];
        $ssFilter = new Zend_Session_Namespace($this->_namespace);
        //$ssFilter->unsetAll();

        if (empty($ssFilter->col)) {
            $ssFilter->keywords = '';
            $ssFilter->col = 'g.id';
            $ssFilter->order = 'DESC';
        }
        $this->_arrParam['ssFilter']['keywords'] = $ssFilter->keywords;
        $this->_arrParam['ssFilter']['col'] = $ssFilter->col;
        $this->_arrParam['ssFilter']['order'] = $ssFilter->order;

        $session = new Zend_Session_Namespace('userinfor');

        if (!isset($session->groupid) || !isset($session->userid)) {
            $auth = new Australian_System_Auth();
            $auth->logout();
        }

        $groupid = $session->groupid;
        $utilities = new Australian_Utilities();
        $this->_arrParam['userinfor']['groupid'] = $groupid;
        $this->_arrParam['userinfor']['userid'] = $session->userid;
        $this->_arrParam['userinfor']['username'] = $session->username;

        // Truyen ra view
        $this->view->arrParam = $this->_arrParam;
        $this->view->currentController = $this->_currentController;
        $this->view->actionMain = $this->_actionMain;
        $this->view->messageSuccess = '';
        $this->view->countNewMessage    = $utilities->countNewMessage();

        parent::init();
        $template_path = TEMPLATE_PATH . "/admin/system";
        $this->loadTemplate($template_path, 'template.ini', 'template');
    }

    public function indexAction() {
        $this->view->Title = 'Member :: Change Password';
        $this->view->headTitle($this->view->Title, true);
        $this->view->Item           = NULL;
        if ($this->_request->isPost()) {
            $validator = new Admin_Form_Changepass($this->_arrParam);
            if ($validator->isError()){
                $this->view->messageError   = $validator->getMessageError();
                $this->view->Item           = $validator->getData();
            } else {
                $tblChangepass              = new Admin_Model_Changepass();
                $tblChangepass->saveItem($this->_arrParam, array('task' => 'admin-edit'));
                $this->view->messageSuccess = 'Chage password success ! ';
            }
            
        }
    }

}